package refactoredBankSystem;

/**
 * The DebitCard class.
 * @author (refactorers) Sagar Kamboj, Yong Yu Wang
 *
 */
public class DebitCard 
{
	/**
	 * The last debit card number.
	 */
	private static int fLastDebitCardNumber;
	
	/**
	 * The account connected to this debit card.
	 */
	private CheckingAccount fAccountConnectedTo;
	
	/**
	 * The debit card number of this debit card.
	 */
	private int fDebitCardNumber;
	
	/**
	 * The current customer of the debit card.
	 */
	private Customer currentCustomer;
	
	/**
	 * Creates a DebitCard with the given customer.
	 * 
	 * @param newCustomer  making a debit card.
	 */
	public DebitCard(final Customer newCustomer)
	{
		// Calling second constructor with
		this(newCustomer, null);
	}
	
	/**
	 * Creates a DebitCard with the given customer,
	 * with a spending limit from the specific account.
	 * 
	 * @param newCustomer making a debit card..
	 * @param account that is used.
	 */
	public DebitCard(final Customer newCustomer, final CheckingAccount account)
	{
		currentCustomer = newCustomer;
		fDebitCardNumber = fLastDebitCardNumber;
		fLastDebitCardNumber++;
		fAccountConnectedTo = account;
	}
	
	/**
	 * Pays off the amount from the balance if possible.
	 * 
	 * @param amount that needs to be payed.
	 * @return if the amount was paid off or not.
	 */
	public boolean pay(final double amount)
	{
		if((fAccountConnectedTo.getBalance() - amount) < -fAccountConnectedTo.getDebitAmount())
		{
			fAccountConnectedTo.setBalance(fAccountConnectedTo.getBalance() - amount);
			return true;
		}
		else
		{
			return false;
		}
	}
	
	 /**
	 * Sets the fLastDebitCardNumber in this class to a new one.
	 * @param fLastDebitCardNumber	the new fLastDebitCardNumber to set.
	 */
	public void setFLastDebitCardNumber(final int newNumber) {
		fLastDebitCardNumber = newNumber;
	}
	
	/**
	 * Gets the fLastDebitCardNumber object associated with this class.
	 * @return the fLastDebitCardNumber 
	 */
	public int getFLastDebitCardNumber() {
		return fLastDebitCardNumber;
	}
	
	/**
	 * Sets the fAccountConnectedTo in this class to a new one.
	 * @param fAccountConnectedTo	the new fAccountConnectedTo to set.
	 */
	public void setFAccountConnectedTo(final CheckingAccount newAccount) {
		fAccountConnectedTo = newAccount;
	}
	
	/**
	 * Gets the fAccountConnectedTo object associated with this class.
	 * @return the fAccountConnectedTo 
	 */
	public CheckingAccount getFAccountConnectedTo() {
		return fAccountConnectedTo;
	}
	
	/**
	 * Sets the fDebitCardNumber in this class to a new one.
	 * @param fDebitCardNumber	the new fDebitCardNumber to set.
	 */
	public void setFDebitCardNumber(final int newNumber) {
		fDebitCardNumber = newNumber;
	}
	
	/**
	 * Gets the fDebitCardNumber object associated with this class.
	 * @return the fDebitCardNumber 
	 */
	public int getFDebitCardNumber() {
		return fDebitCardNumber;
	}
	
	/**
	 * Get the current customer belonging to this class.
	 * @return	The current customer in this class.
	 */
	public Customer getCustomer() {
		return currentCustomer;
	}
	
	/**
	 * Sets the customer in this class to a new one.
	 * @param newCustomer	the new customer to set.
	 */
	public void setCustomer(final Customer newCustomer) {
		currentCustomer = newCustomer;
	}

}
